package com.elong.android.specialhouse.payment;

import android.content.Context;

import com.dp.android.elong.crash.LogWriter;
import com.elong.android.specialhouse.AppConstants;
import com.elong.android.specialhouse.IConfig;
import com.elong.myelong.usermanager.User;
import com.elong.payment.PaymentConfig;
import com.elong.payment.utils.PaymentLogWriter.LogWriterClient;
import com.elong.payment.utils.UserClientUtil.UserClient;

public class PaymentHelper {

	public static void initPayment(Context context) {

//		// 网络模块初始化
//		NetConfig.init(context);
//		NetConfig.setApiKey(AppConstants.NEW_API_SECRET_KEY);
//		NetConfig.setSessionClient(new ISessionClient() {
//			@Override
//			public String getSession() {
//				return User.getInstance().getSessionToken();
//			}
//
//			@Override
//			public String getDeviceId() {
//				return Utils.getDeviceID(ApartmentApplication.getContext());
//			}
//		});

		// 初始化支付相关信息
//		PaymentConfig.setWxPayActivity(WXPayEntryActivity.class);
		PaymentConfig.setDebugHttpActivity(null);

		PaymentConfig.setDebugOn(IConfig.DEBUG_ON);
//		PaymentConfig.setWxAppKey(AppConstants.WEIXIN_APPID);
		PaymentConfig.setWxUseable(false);
		PaymentConfig.useHttpsForPayment(true);
		PaymentConfig.setPaymentChannel(AppConstants.PAYMENT_CHANNEL_TYPE);
//		PaymentConfig.setAPIUrl(AppConstants.SERVER_URL_TEST);
		PaymentConfig.setAPIUrl(IConfig.PAYMENT_ROOT_URL);
		PaymentConfig.setAutoTestOn(false);
//		/**
//		 * 页面跳转工具注册
//		 */
//		PaymentConfig.setCAPwdResetClient(new CAPwdResetClient() {
//			@Override
//			public Intent getCAPwdIntent(Activity context) {
//				try {
//					return Mantis.getPluginIntent(context, ActivityConfig.MyElongCashSetPwdActivity.getPackageName(),
//							ActivityConfig.MyElongCashSetPwdActivity.getAction());
//				} catch (NameNotFoundException e) {
//					return null;
//				}
//			}
//		});

//		/**
//		 * 打点工具注册
//		 */
//		PaymentConfig.setCountlyUtil(new CountlyClient() {
//
//			@Override
//			public void UserClientSpotClick(String pageName, String eventName) {
//				EventReportTools.sendPageSpotEvent(pageName, eventName);
//			}
//
//			@Override
//			public void UserClientPageOpen(String page, String channel) {
//				.sendPageOpenEvent(page, channel);
//
//			}
//
//			@Override
//			public void UserClientPageInfo(String pagename, String paramaction) {
//				EventReportTools.sendPageInfoEvent(pagename, paramaction);
//
//			}
//		});

		PaymentConfig.setLogWriter(new LogWriterClient() {

			@Override
			public void sendCrashLogToServer(Exception e, int type) {
				LogWriter.sendCrashLogToServer(e, type);
			}

			@Override
			public void logException(String tag, String info, Exception e) {
				LogWriter.logException(tag, info, e);
			}
		});

		PaymentConfig.setUserClient(new UserClient() {

			@Override
			public void setHasSetPwdForCashAccount(boolean set) {
				User.getInstance().setHasSetPwdForCashAccount(set);
			}

			@Override
			public boolean isLogin() {
				return User.getInstance().isLogin();
			}

			@Override
			public boolean isHasSetPwdForCashAccount() {
				return User.getInstance().isHasSetPwdForCashAccount();
			}

			@Override
			public String getSessionToken() {
				return User.getInstance().getSessionToken();
			}

			@Override
			public String getPassword() {
				return User.getInstance().getPassword();
			}

			@Override
			public long getCardNo() {
				return User.getInstance().getCardNo();
			}
		});
	}

	/**
	 * 适配主APP的网络环境切换
	 */
	public static void updateServerURL(String url) {
		PaymentConfig.setAPIUrl(url);
	}

}
